package lib.self.util.view;

import android.app.ActionBar.LayoutParams;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

/**
 * description: 获取Layout param专用
 * author: Steven Xiao
 * date: 2017/5/3
 */
public class LayoutUtil {
    public static final int MATCH_PARENT = LayoutParams.MATCH_PARENT;
    public static final int WRAP_CONTENT = LayoutParams.WRAP_CONTENT;
    public static final int MIN_POSITIVE_VALUE = 1;//最小的正数

    public static RelativeLayout.LayoutParams getRelativeParams(int w, int h) {
        return new RelativeLayout.LayoutParams(w, h);
    }

    public static LinearLayout.LayoutParams getLinearParams(int w, int h) {
        return new LinearLayout.LayoutParams(w, h);
    }

    public static ViewGroup.LayoutParams getViewGroupParams(int w, int h) {
        return new ViewGroup.LayoutParams(w, h);
    }

    public static void setLayoutParams(View view, int w, int h) {
        ViewGroup.LayoutParams params = view.getLayoutParams();
        params.width = w;
        params.height = h;
        view.setLayoutParams(params);
    }

    /**
     * RecyclerView 头尾专用
     */
    public static void setHeaderOrFooterParams(View view, int w, int h) {
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
        if (params == null) {
            params = new RecyclerView.LayoutParams(w, h);
            view.setLayoutParams(params);
        } else {
            params.width = w;
            params.height = h;
            view.setLayoutParams(params);
        }
    }
}


